# Which compiler
# CC = gcc
# AR = ar
# AT = @

include $(PROJ_ROOT_PATH)/board.mk
include $(PROJ_ROOT_PATH)/config.mk

OUTPUT = luaarch


# source file
SRCS += main.c
SRCS += lua_arch/core.c
SRCS += lua_arch/comm.c
SRCS += lua_arch/testcase.c
SRCS += lua_arch/module/module.c
SRCS += lua_arch/module/gpio.c
SRCS += lua_arch/module/pwm.c
SRCS += lua_arch/module/uart.c
SRCS += lua_arch/module/timer.c
SRCS += lua_arch/module/dnalua.c
SRCS += lua_arch/module/script.c

OBJS = $(patsubst %.c,%.o,$(SRCS))

LIBS += -lpthread
LIBS += -luart
LIBS += -llua
LIBS += -lsyscom
LIBS += -lbipbuffer
LIBS += -lm

# Where are include files kept
INCLUDES += -Ilua_arch
INCLUDES += -Ilua_arch/cjson
INCLUDES += -Ilua_arch/module
INCLUDES += -I$(BUS_PATH)/uart
INCLUDES += -I$(MIDDLEWARE_PATH)/lua
INCLUDES += -I$(MIDDLEWARE_PATH)/lua/lua-5.3.0/src
# INCLUDES += -I$(MIDDLEWARE_PATH)/lua/lua-dna
INCLUDES += -I$(MIDDLEWARE_PATH)/syscom

# Option for development
CFLAGS += -g -O2 -Wall
# Option for release
# CFLAGS = -O -Wall

CFLAGS += -D$(OS)


$(OUTPUT): $(OBJS)
# 	$(AT)echo "LIBS: $(LIBS)"
	$(AT)$(CC) $^ -o $(BIN_PATH)$@ $(INCLUDES) $(LIBS) -L$(LIBS_PATH)
# 	$(AT)echo "$(OUTPUT) linking done"

# $(OBJS): $(SRCS)
$(OBJS):%.o:%.c
# 	$(AT)echo "SRCS: $(SRCS)"
# 	$(AT)echo "OBJS: $(OBJS)"
# 	$(AT)echo "CFLAGS: $(CFLAGS)"
	$(AT)$(CC) -c $< $(CFLAGS) $(INCLUDES) $(LIBS) -o $@
# 	$(AT)echo "$(OBJS) compiling done"


.PHONY: clean
clean:
	$(AT)-rm -rf $(OBJS)

